package leetcode_2501_2600;

import org.omg.CORBA.INTERNAL;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class LeeCode_2588 {
    public static void main(String[] args) {
        System.out.println(beautifulSubarrays(new int[]{4, 3, 1, 2, 4}));
    }
    private static long beautifulSubarrays(int[] nums) {
        long ans = 0;
        int n = nums.length;
        int[] sums = new int[n + 1];
        Map<Integer, Integer> map = new HashMap<>();
        map.put(0, 1);
        for (int i = 1; i <= n; i++) {
            sums[i] = sums[i - 1] ^ nums[i - 1];
            map.put(sums[i], map.getOrDefault(sums[i], 0) + 1);
        }
        for (Integer key : map.keySet()) {
            int c = map.get(key);
            ans += ((long) c * (c - 1)) >>> 1;
        }
        return ans;
    }
}
